package com.init.bootframe.system.controller;

import com.init.bootframe.system.service.IRoleService;
import com.init.bootframe.system.vo.RoleModuleVO;
import com.init.bootframe.system.vo.RoleVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 角色controller
 */
@RestController
@RequestMapping("/role")
public class RoleController {
    private Logger logger = LoggerFactory.getLogger(RoleController.class); // 日志

    @Autowired
    private IRoleService roleService; // 角色service

    /**
     * 查新角色列表
     * @param roleVO
     * @return
     * @throws Exception
     */
    @PostMapping("/findRoleList")
    public Map<String, Object> findRoleList(@RequestBody RoleVO roleVO) throws Exception {
        Map<String, Object> result = roleService.findRoleList(roleVO);
        return result;
    }

    /**
     * 添加角色
     * @param roleVO
     * @return
     * @throws Exception
     */
    @PostMapping("/addRole")
    public Map<String, Object> addRole(@RequestBody RoleVO roleVO) throws Exception {
        Map<String, Object> result = roleService.addRole(roleVO);
        return result;
    }

    /**
     * 更新角色
     * @param roleVO
     * @return
     * @throws Exception
     */
    @PostMapping("/updateRole")
    public Map<String, Object> updateRole(@RequestBody RoleVO roleVO) throws Exception {
        Map<String, Object> result = roleService.updateRole(roleVO);
        return result;
    }

    /**
     * 删除角色
     * @param roleVO
     * @return
     * @throws Exception
     */
    @PostMapping("/deleteRole")
    public Map<String, Object> deleteRole(@RequestBody RoleVO roleVO) throws Exception {
        Map<String, Object> result = roleService.deleteRole(roleVO);
        return result;
    }

    /**
     * 角色详情查询
     * @param roleVO
     * @return
     * @throws Exception
     */
    @PostMapping("/findRole")
    public RoleVO findRole(@RequestBody RoleVO roleVO) throws Exception {
        RoleVO result = roleService.findRole(roleVO);
        return result;
    }

    /**
     * 角色授权
     * @param roleVO
     * @return
     * @throws Exception
     */
    @PostMapping("/updateRoleAuth")
    public Map<String, Object> updateRoleAuth(@RequestBody RoleVO roleVO) throws Exception {
        Map<String, Object> result = roleService.updateRoleAuth(roleVO);
        return result;
    }

    /**
     * 查询有效角色集合
     * @param roleVO
     * @return
     * @throws Exception
     */
    @PostMapping("/findRoles")
    public List<RoleVO> findRoles(@RequestBody RoleVO roleVO) throws Exception {
        List<RoleVO> result = roleService.findRoles(roleVO);
        return result;
    }

    /**
     * 查询有效角色功能集合
     * @param roleModuleVO
     * @return
     * @throws Exception
     */
    @PostMapping("/findRoleModuleList")
    public List<RoleModuleVO> findRoleModuleList(@RequestBody RoleModuleVO roleModuleVO) throws Exception {
        List<RoleModuleVO> result = roleService.findRoleModuleList(roleModuleVO);
        return result;
    }
}
